package activity.store;

import android.app.Activity;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.alipay.sdk.app.PayTask;
import com.itboye.hutoubenjg.R;
import com.tencent.mm.sdk.modelpay.PayReq;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.unionpay.UPPayAssistEx;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Map;
import java.util.Observable;
import java.util.Observer;
import java.util.Timer;
import java.util.TimerTask;

import alipay.OrderInfoUtil2_0;
import alipay.PayResult;
import base.BaseActivity;
import bean.GoPayBean;
import bean.WeiXinPayBean;
import presenter.DingDanPresenter;
import presenter.SysTemMessgelPresenter;
import presenter.SysTemPresenter;
import util.EdiTextPut;
import util.utls.ByAlert;
import util.utls.Const;
import util.utls.IsUtilUid;
import util.utls.MyGongJv;
import util.utls.SPUtils;
import util.utls.TimeFormat;
import util.volley.ResultEntity;

import static util.EdiTextPut.getTime;

/**
 * 支付
 */
public class GoPayActivity extends BaseActivity implements Observer {

    ImageView back, img_yinhang_check, img_weixin_check, img_qianbao_check, img_zhifubao_check;
    TextView tvTitle, queren;
    private int payType = 1;//默认为1支付宝
    boolean isZFB = true, isYE, isWX;

    TextView tv_time;

    GoPayBean list;
    String count;
    String type;
    String order_code;
    private IWXAPI api;

    DingDanPresenter dingDanPresenter;
    DingDanPresenter dingDanPresenter01;
    String uid;
    GoPayBean dingdanBbean;
    WeiXinPayBean weixinBean;
    GoPayBean bean;
    SysTemMessgelPresenter sysTemMessgelPresenter;
    SysTemPresenter presenter;
    public static String GOUWUINEXIT = "gouwu.end.exit";// 余额支付购物结束
    private boolean isYinHangKa = false;

    String time;
    private long mMin;
    private long onTime;
    private String newsTime;
    private long maxMain = 14;
    long max;
    Timer timer = new Timer();

    boolean isZhiFu=false;//用来标记商品是否过了支付时间

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_go_pay);
        tvTitle.setText(R.string.quzhifu);
        dingDanPresenter = new DingDanPresenter(this);
        dingDanPresenter01 = new DingDanPresenter(this);
        presenter= new SysTemPresenter(this);
        sysTemMessgelPresenter = new SysTemMessgelPresenter(this);
        uid = (String) SPUtils.get(this, null, Const.ID, "");
        showExtraDialog();
        api = WXAPIFactory.createWXAPI(this, Const.APP_ID);
        api.registerApp(Const.APP_ID);
        count = getIntent().getStringExtra("count");
        order_code = getIntent().getStringExtra("order_code");
        type = getIntent().getStringExtra("type");
        list = (GoPayBean) getIntent().getSerializableExtra("bean");
        //银联支付成功
        IntentFilter filter1 = new IntentFilter("zhifu.jieshu");
        registerReceiver(zhifuBroadcastReceiver, filter1);
        //微信支付成功
        IntentFilter filter2 = new IntentFilter(GOUWUINEXIT);
        registerReceiver(zhifuBroadcastReceiver, filter2);

        //重新登录的时候推出该页面
        IntentFilter intentFilter = new IntentFilter("chaingLogin");
        registerReceiver(zhifuBroadcastReceiver, intentFilter);

        try {
            time = getIntent().getStringExtra("time");
            if(time!=null&&!time.equals("")){
                EdiTextPut.getStandardDate(time);
                mMin = Long.valueOf(getTime()).longValue();
                max = maxMain - mMin;
                newsTime = TimeFormat.getOnData();
                onTime = 60 - Long.valueOf(newsTime).longValue();
                if (max < 0) {
                    tv_time.setVisibility(View.GONE);
                    isZhiFu=true;
                }
                timer.schedule(task, 1000, 1000);
            }

        } catch (Exception e) {
        }

    }
    TimerTask task = new TimerTask() {
        @Override
        public void run() {
            runOnUiThread(new Runnable() {      // UI thread
                @Override
                public void run() {
                    onTime--;
                    if (onTime < 0) {
                        max--;
                        tv_time.setText(max + "分钟" + onTime + "秒");
                        onTime = 59;
                        if (max < 0) {
                            max = 0;
                        }
                    }
                    if (max == 0 && onTime == 0) {
                        timer.cancel();
                        tv_time.setVisibility(View.GONE);
                        isZhiFu=true;
                    }
                    tv_time.setText(max + "分钟" + onTime + "秒");
                }
            });
        }
    };
    BroadcastReceiver zhifuBroadcastReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            finish();
        }

        ;
    };

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(zhifuBroadcastReceiver);
    }

    @Override
    protected void onInit() {

    }

    @Override
    protected void onReadIntent(Bundle bundle) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.queren:
//                if(isZhiFu){
//                    ByAlert.alert("该商品已经过了支付时间，请重新下单");
//                    return;
//                }
                switch (payType) {
                    case 1:
                        try {
                            isZFB = true;
                            isYE = false;
                            isWX = false;
                            isYinHangKa = false;
                            zhifubaoPay();
                        } catch (Exception e) {
                        }
                        break;
                    case 2:
                        try {
                            isZFB = false;
                            isYE = true;
                            isWX = false;
                            isYinHangKa = false;
                            //qianBaoPay();
                            dialog.show();
                        } catch (Exception e) {
                        }

                        break;
                    case 3:
                        try {
                            isZFB = false;
                            isYE = false;
                            isWX = true;
                            isYinHangKa = false;
                            weixinPay();
                        } catch (Exception e) {
                        }
                        break;
                    case 4:
                        try {
                            isZFB = false;
                            isYE = false;
                            isWX = false;
                            isYinHangKa = true;
                            beginBankPay();
                        } catch (Exception e) {
                        }
                        break;
                }
                break;
            case R.id.img_zhifubao_check:
                setPayTypeSelected(1);
                break;
            case R.id.img_qianbao_check:
                setPayTypeSelected(2);
                break;
            case R.id.img_weixin_check:
                setPayTypeSelected(3);
                break;
            case R.id.img_yinhang_check:
                setPayTypeSelected(4);
                break;
        }
    }


    Runnable bankRunnable = new Runnable() {
        @Override
        public void run() {
            String tn = null;
            InputStream is;
            try {
                String url = Const.TN_URL_01 + "?pay_code=" + order_code;
                URL myURL = new URL(url);
                URLConnection ucon = myURL.openConnection();
                ucon.setConnectTimeout(120000);
                is = ucon.getInputStream();
                int i = -1;
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                while ((i = is.read()) != -1) {
                    baos.write(i);
                }

                tn = baos.toString();
                is.close();
                baos.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println("支付消息" + tn);
            Message msg = mBankHandler.obtainMessage();
            msg.obj = tn;
            mBankHandler.sendMessage(msg);
        }
    };

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data == null) {
            return;
        }
        String msg = "";
        /*
         * 支付控件返回字符串:success、fail、cancel 分别代表支付成功，支付失败，支付取消
         */
        String str = data.getExtras().getString("pay_result");
        if (str.equalsIgnoreCase("success")) {

            // 如果想对结果数据验签，可使用下面这段代码，但建议不验签，直接去商户后台查询交易结果
            // result_data结构见c）result_data参数说明
            if (data.hasExtra("result_data")) {
                String result = data.getExtras().getString("result_data");
                try {
                    JSONObject resultJson = new JSONObject(result);
                    String sign = resultJson.getString("sign");
                    String dataOrg = resultJson.getString("data");
                    // 此处的verify建议送去商户后台做验签
                    // 如要放在手机端验，则代码必须支持更新证书
//                    boolean ret = verify(dataOrg, sign, mMode);
//                    if (ret) {
                    // 验签成功，显示支付结果
                    msg = "支付成功！";
//                    } else {
//                        // 验签失败
//                        msg = "支付失败！";
//                    }
                } catch (JSONException e) {
                }
            }
        } else if (str.equalsIgnoreCase("fail")) {
            msg = "支付失败！";
        } else if (str.equalsIgnoreCase("cancel")) {
            msg = "用户取消了支付";
        }
        ByAlert.alert(msg);
    }

    private String tn;
    private final String mMode = "00";
    Handler mBankHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            tn = (String) msg.obj;
            /*************************************************
             * 步骤2：通过银联工具类启动支付插件
             ************************************************/
            doStartUnionPayPlugin(GoPayActivity.this, tn, mMode);
        }
    };

    public void doStartUnionPayPlugin(Activity activity, String tn, String mode) {
        UPPayAssistEx.startPay(activity, null, null, tn, mode);
    }

    /**
     * 支付宝支付
     */
    private void zhifubaoPay() {
        if (type != null) {
            showProgressDialog("请稍后", true);
            if (type.equals("one")) {//判断是立即购买还是重新支付
                lijizhifu(list);
            } else if (type.equals("two")) {//重新支付
                dingDanPresenter.chongxinGouMai(IsUtilUid.sId(), uid, order_code);
            }
        }
    }

    /**
     * 钱包支付
     */
    private void qianBaoPay() {
        if (type != null) {
            showProgressDialog("请稍后", true);
            if (type.equals("one")) {//判断是立即购买还是重新支付
                lijizhifu(list);
            } else if (type.equals("two")) {//重新支付
                dingDanPresenter.chongxinGouMai(IsUtilUid.sId(), uid, order_code);
            }
        }
    }

    /**
     * 微信支付
     */
    private void weixinPay() {
        if (type != null) {
            showProgressDialog("请稍后", true);
            if (type.equals("one")) {
                lijizhifu(list);
            } else if (type.equals("two")) {
                dingDanPresenter.chongxinGouMai(IsUtilUid.sId(), uid, order_code);
            }
        }
    }

    private void beginBankPay() {
        //   new Thread(bankRunnable).start();
        if (type != null) {
            showProgressDialog("请稍后", true);
            if (type.equals("one")) {
                lijizhifu(list);
            } else if (type.equals("two")) {
                dingDanPresenter.chongxinGouMai(IsUtilUid.sId(), uid, order_code);
            }
        }
    }
    /**
     * 立即购买
     * @param bean
     */
    private void lijizhifu(GoPayBean bean){
        if (isZFB) {
            System.out.print("isZFB");
            zfb(bean);
        } else if (isWX) {
            dingDanPresenter.WeiXinPay(bean.getPay_code(), "1");
        } else if (isYE) {
            dingDanPresenter01.yueZhiFu(uid, bean.getPay_code());
        } else if (isYinHangKa) {
            Intent intent = new Intent(this, YinLianWebActivity.class);
            intent.putExtra("url", Const.zhifu + bean.getPay_code());
            intent.putExtra("title", "银联支付");
            startActivity(intent);
            try {
                closeProgressDialog();
            } catch (Exception e) {
            }
        }
    }
    /**
     * @param type 支付方式的选中状态
     *             1、支付宝
     *             2、钱包
     *             3、微信
     */
    public void setPayTypeSelected(int type) {
        clearAllSelected();
        switch (type) {
            case 1:
                img_zhifubao_check.setBackgroundResource(R.drawable.pay_type_selected);
                break;
            case 2:
                img_qianbao_check.setBackgroundResource(R.drawable.pay_type_selected);
                break;
            case 3:
                img_weixin_check.setBackgroundResource(R.drawable.pay_type_selected);
                break;
            case 4:
                img_yinhang_check.setBackgroundResource(R.drawable.pay_type_selected);
                break;
        }
        payType = type;
    }

    public void clearAllSelected() {
        img_zhifubao_check.setBackgroundResource(R.drawable.pay_type_unselected);
        img_qianbao_check.setBackgroundResource(R.drawable.pay_type_unselected);
        img_weixin_check.setBackgroundResource(R.drawable.pay_type_unselected);
        img_yinhang_check.setBackgroundResource(R.drawable.pay_type_unselected);

    }


    @Override
    public void update(Observable observable, Object data) {
        ResultEntity entity = handlerError(data);
        if (entity != null) {
            IsUtilUid.tianjia(entity);
            //重新支付订单
            if (entity.getEventType() == DingDanPresenter.chongxin_goumai_success) {
                bean = (GoPayBean) entity.getData();
                System.out.print("update");
                if (isZFB) {
                    System.out.print("isZFB");
                    zfb(bean);
                } else if (isWX) {
                    dingDanPresenter.WeiXinPay(bean.getPay_code(), "1");
                } else if (isYE) {
                    dingDanPresenter01.yueZhiFu(uid, bean.getPay_code());
                } else if (isYinHangKa) {
                    Intent intent = new Intent(this, YinLianWebActivity.class);
                    intent.putExtra("url", Const.zhifu + bean.getPay_code());
                    intent.putExtra("title", "银联支付");
                    startActivity(intent);
                }
            }
            if (entity.getEventType() == DingDanPresenter.chongxin_goumai_fail) {
                bean = (GoPayBean) entity.getData();
            }

            //微信预支付
            if (entity.getEventType() == DingDanPresenter.weixin_pay_success) {
                weixinBean = (WeiXinPayBean) entity.getData();
                PayReq req = new PayReq();
                req.appId = Const.APP_ID;
                req.partnerId = weixinBean.getPartnerid();
                req.prepayId = weixinBean.getPrepayid();
                req.nonceStr = weixinBean.getNoncestr();
                req.timeStamp = weixinBean.getTimestamp();
                req.packageValue = "Sign=WXPay";
                req.sign = weixinBean.getSign();
                boolean is = api.sendReq(req);
                if (is) {
//                    ByAlert.alert("已调其成功");
//                    finish();
//                    // 发送广播通知LoginActivity结束
//                    Intent intent1 = new Intent(GOUWUINEXIT);
//                    sendBroadcast(intent1);
                } else {

                    ByAlert.alert("调起微信支付失败");

                }
            }
            if (entity.getEventType() == DingDanPresenter.weixin_pay_fail) {
                bean = (GoPayBean) entity.getData();
            }
            //余额支付
            if (entity.getEventType() == DingDanPresenter.yue_success) {
                ByAlert.alert(entity.getData());
                finish();
                // 发送广播通知LoginActivity结束
                Intent intent1 = new Intent(GOUWUINEXIT);
                sendBroadcast(intent1);
            }
            if (entity.getEventType() == DingDanPresenter.yue_fail) {
                ByAlert.alert(entity.getData());
            }
            if (entity.getEventType() == presenter.Secret_success) {
                qianBaoPay();
                try {
                    closeProgressDialog();
                    dialog.dismiss();
                } catch (Exception e) {
                }
            }
        }
        try {
            closeProgressDialog();
        } catch (Exception e) {
        }
    }

    /**
     * 支付宝支付业务：入参app_id
     */
    public static final String APPID = "2016122704665497";

    /**
     * 支付宝账户登录授权业务：入参pid值
     */
    public static final String PID = "2088221666614017";
    /**
     * 支付宝账户登录授权业务：入参target_id值
     */
    public static final String TARGET_ID = "";

    /**
     * 商户私钥，pkcs8格式
     */
    public static final String RSA_PRIVATE = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCsNiOkk2F22n5WgY/6qUhMFSLU03IB4OSpOzB3/kTXRQUvQVRCmikKLTlRQgHPbQfdUrRycIWK3+GDeXfqK7mr9Nb8KZzpjNteCdD1z+TA/xbcHumPd4v3Z7pcYdoFGdVmvyxUDcnn1DUHlDHeEKez3CSGl1zHUIyKYW0ypEX5BNL4KWC/rch/Ycr9mQhp+83vml7ccLBL22LD6MUyp8h0x2JYEouaJQ4ptNagZdt3FOiGIptTJm5FjHUw9Dyh8BdToxY0nPcRLckQiW6NE7a7fx9Phxpa9/USVmsxIU3muD0qIgVUATVxIfQfhDkH31Q+ovNezARgvDdA5qEph7dtAgMBAAECggEALk18NeLeoMtMjsvVP4tGghZowBp+G90w/gOJG6pFLjBDnZoOIr46bJ8OOzfpLrFdHPgAxohUj6t0ghol0NOi34Y8S56QrwcNcHJpOb6E/hNYPSUenVGCU6oTJIW2zgpNI4whShRPBkM7YudIpTGLNcPqGjoWWwzgTNC3QJeErNhan/FcqxwiMX0+ag9lELU7Fzz4XnW3keUu+eAszjbOlSjdGiCjKiDVlctQQ1blgKAh2+ArRSeRmXkxgUXrFO69zO7fr4YvHPJiB6PPPgNHQRL8LsTPjWxY+5EbvnlGXou791Gdf+chRTq3p6P5zZuNr6xgAWzuHdQolIa2jkDqbQKBgQDqLKG+yg7q/e9Oy28u7McJ8uGXY1AFo7zQnv8tFCZV8iSHtmto1p5t4DV3XfY8cdfYQji0NwdBHtRctu93LRmVgLtcpbPGrjVDElfBvPisKZ8QdEHG/WtXDwuZwKKimy/1sL0OEskCrndRIkJbgs65QPG4vUEBLcgJIpmle88rdwKBgQC8QxT3xSwS/ThuowVLhNCGQ9JPkPtFVCaFBkGF5S7uN7y5jRIAGmO4Hl1yt7vWhlrw2voG4M5JkVCgbIt//C84Pl/ZT5ln5YrWITWKjuVXayAQsM4h3V5/xD0oPIq+iGsOQv4fuPruQU7v1nyyn9ILB08cW3mObO56q+5cO6OlOwKBgQDdwfJR6KsD4gFzTrc1ash6JWV4pXWsQYiWz1q656/+B9aMJjXFDCjvyDkZlwON7gkHJH7qOopGItncCujupOjraQMFE24RofuSTpaIQ1oCP1AAlveLZ4T05qyHp6Lb9bYPJpWB9Ewim/EmBhls64y0ZkoCNkaOxTn/XKK/0WU4tQKBgBf13bRPJvXfvo/uNZ1P8Q41kY3I4QII3MIvcqVs7tUoyN9Awhq7QRfM3Y3dLo32GZrv88RuVjLsyLsyNWr7mLLq1V4eEGM1xr7MCTlySGQg4Trelc2flAhk3HfDhNENIbr18cvtyhoKu9YwkTxWtO/sZTgxuD3VRWDdgv/AI2rDAoGAFSj4/5YC1SwOZnVqMdA69wJUxEyBBWpwBU2Gln3IgggtVIkbLYk7P5PwWgTmShz0NmQgCKon0Eu8M1AI3fbZJUAAZdtnqHgJ+9synjqnsOTXdRKmCcaS9s/W3pVrQ6yEsCN2vK+7gMQN2MhKJTO5IYQmUyVWRh2+a5n3i41fwps=";

    private static final int SDK_PAY_FLAG = 1;

    /**
     * 支付宝
     */
    private void zfb(GoPayBean bean) {
        /**
         * 这里只是为了方便直接向商户展示支付宝的整个支付流程；所以Demo中加签过程直接放在客户端完成；
         * 真实App里，privateKey等数据严禁放在客户端，加签过程务必要放在服务端完成；
         * 防止商户私密数据泄露，造成不必要的资金损失，及面临各种安全风险；
         * orderInfo的获取必须来自服务端；
         */
        String money = bean.getPay_money();
        double m = Double.parseDouble(money) / 100;
        String content = bean.getPay_code();
        String code = bean.getPay_code();
        String time = bean.getCreate_time();
        Map<String, String> params = OrderInfoUtil2_0.buildOrderParamMap(APPID, m + "", content, code, time);
        String orderParam = OrderInfoUtil2_0.buildOrderParam(params);
        String sign = OrderInfoUtil2_0.getSign(params, RSA_PRIVATE);
        final String orderInfo = orderParam + "&" + sign;


        Runnable payRunnable = new Runnable() {

            @Override
            public void run() {
                PayTask alipay = new PayTask(GoPayActivity.this);
                Map<String, String> result = alipay.payV2(orderInfo, true);

                Message msg = new Message();
                msg.what = SDK_PAY_FLAG;
                msg.obj = result;
                mHandler.sendMessage(msg);
            }
        };

        Thread payThread = new Thread(payRunnable);
        payThread.start();
    }

    private Handler mHandler = new Handler() {
        @SuppressWarnings("unused")
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case SDK_PAY_FLAG: {

                    PayResult payResult = new PayResult((Map<String, String>) msg.obj);
                    /**
                     对于支付结果，请商户依赖服务端的异步通知结果。同步通知结果，仅作为支付结束的通知。
                     */
                    String resultInfo = payResult.getResult();// 同步返回需要验证的信息
                    String resultStatus = payResult.getResultStatus();
                    // 判断resultStatus 为9000则代表支付成功
                    if (TextUtils.equals(resultStatus, "9000")) {
                        // 该笔订单是否真实支付成功，需要依赖服务端的异步通知。
                        Toast.makeText(GoPayActivity.this, "支付成功", Toast.LENGTH_SHORT).show();
                        finish();
                        // 发送广播通知LoginActivity结束
                        Intent intent1 = new Intent(GOUWUINEXIT);
                        sendBroadcast(intent1);
                    } else {
                        // 该笔订单真实的支付结果，需要依赖服务端的异步通知。(注：如果没有安装支付宝客户端选择其他支付会出现异常，所以没有安装支付宝客户端的时候结束掉页面)
                        if (MyGongJv.isAvilible(GoPayActivity.this, "com.eg.android.AlipayGphone")) {

                            Toast.makeText(GoPayActivity.this, "支付失败", Toast.LENGTH_SHORT).show();
                        }else{
                            Toast.makeText(GoPayActivity.this, "支付失败,检测到手机没有安装支付宝，请到订单中支付", Toast.LENGTH_SHORT).show();
                            finish();
                            // 发送广播通知LoginActivity结束
                            Intent intent1 = new Intent(GOUWUINEXIT);
                            sendBroadcast(intent1);
                        }
                        try {
                            closeProgressDialog();
                        } catch (Exception e) {
                        }
                    }
                    break;
                }

                default:
                    break;
            }
        }

        ;
    };

    private Dialog dialog;// 自定义Dialog
    /**
     * 自定义Dialog
     */
    private void showExtraDialog() {
        dialog = new Dialog(GoPayActivity.this, R.style.rel_dialog);
        View view = LayoutInflater.from(GoPayActivity.this).inflate(
                R.layout.dialog_normal_layout, null);
        dialog.setContentView(view);
        final EditText dialog_et = (EditText) view.findViewById(R.id.dialog_et);
        TextView user_title = (TextView) view.findViewById(R.id.user_title);
        user_title.setText("输入您的6位支付密码");
        dialog_et.setText("");
        TextView dialog_ok = (TextView) view.findViewById(R.id.dialog_ok);
        TextView dialog_quxiao = (TextView) view.findViewById(R.id.dialog_quxiao);
        dialog.setCanceledOnTouchOutside(false);
        dialog_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                dialog.dismiss();
            }
        });
        dialog_quxiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {

                if(dialog_et.getText().toString().equals("")){
                    ByAlert.alert("请输入支付密码");
                }else {
                    showProgressDialog("验证中..", true);
                    presenter.oncheckSecret(IsUtilUid.isUid(), dialog_et.getText().toString());
                    dialog.dismiss();
                }
            }
        });
        WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        // 屏幕宽度
        int screenWidth = display.getWidth();
        // 屏幕高度
        int screenHeight = display.getHeight();
        Window window = dialog.getWindow();

        WindowManager.LayoutParams lp = window.getAttributes();
        window.setGravity(Gravity.CENTER);
        lp.width = screenWidth * 3 / 4;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);

    }
}
